define(function (require) {
    var $ = require("zepto");
    var global = require("global");
    var video = {
        _video: $(".j-video"),
        _videoArr: [],
        video_init: function () {
            var that = this;
            that._video.each(function () {
                var tmp_video;
                var src = $(this).attr("data-video-src");
                var type = $(this).attr("data-video-type");
                var $img = $(this).find(".img");
                var $video = $(this).find(".video");
                switch (type) {
                    case 'bendi':
                        tmp_video = that.bendi_video(src);
                        break;
                    case 'qq':
                        tmp_video = that.qq_video(src);
                        break;
                    case 'youku':
                        tmp_video = that.youku_video(src);
                        break;
                }
                $(this).find(".videoWrap").append($(tmp_video));
                that._videoArr.push(tmp_video);
                $img.on("click", function () {
                    $(this).hide();
                    if ("IFRAME" === tmp_video.nodeName && $(tmp_video).data("src")) {
                        tmp_video.src = $(tmp_video).data("src");
                    }
                    $video.removeClass("f-hide");
                    setTimeout(function () {
                        $video.addClass("z-show"), setTimeout(function () {
                            "function" === typeof tmp_video.play && tmp_video.play();
                        }, 500);
                    }, 20);
                    global._handleEvent("video_open", tmp_video);
                });
                $video.on("click", function (event) {
                    var element = event.target;
                    if (!$(element).hasClass("videoWrap") && !$(element).parents(".videoWrap").length >= 1) {
                        $video.removeClass("z-show");
                        $img.show();
                        if ("function" === typeof tmp_video.pause) {
                            tmp_video.pause();
                        }
                        if ("IFRAME" === tmp_video.nodeName) {
                            $(tmp_video).data("src", tmp_video.src);
                            tmp_video.src = "";
                        }
                        setTimeout(function () {
                            $video.addClass("f-hide");
                            global._handleEvent("video_close", tmp_video);
                        }, 500);
                    }
                });
            });
        },
        bendi_video: function (src) {
            var option = {controls: "controls", preload: "none", src: src};
            var container = $("<video></video>")[0];
            for (var a in option) {
                option.hasOwnProperty(a) && a in container && (container[a] = option[a]);
            }
            return container;
        },
        qq_video: function (src) {
            return $('<iframe src="' + src + '" frameborder=0 allowfullscreen></iframe>')[0];
        },
        youku_video: function (src) {
            return $('<iframe src="' + src + '" frameborder=0 allowfullscreen></iframe>')[0];
        }};
    return video;
});